package ajax;

import beans.MainBean;

import com.google.gson.JsonObject;

public class MessagesAjaxBean extends MainBean {
	

	private JsonObject jsonRes = new JsonObject();
	
	public MessagesAjaxBean() {
		super();
	}
	public String getRunAjax(){
		choiseMethod();
		return jsonRes.toString();
	}
	public JsonObject getJsonRes() {
		return jsonRes;
	}
	public void addPropertyToRes(String property,String value){
		jsonRes.addProperty(property, value);
	}
	private void choiseMethod(){
		try{
			String act = getStringFromParam("action") ;
			if( act != null && !act.isEmpty() ){
				MessagesAjaxActions action = MessagesAjaxActions.getActionFromString( act );
				action.doAction(this);
				jsonRes.addProperty("status", "ok");
				Thread.sleep(3000);
			}
		}catch (Exception e) {
			jsonRes.addProperty("status", "error");
		}
	}
}
